<template>
  <div class="video-wrapper" id="boxShow"  @touchstart.stop="dragDiv"  @touchend.stop="dragUp">
    <video src="http://oss.handi.fit/videos/comment/202304271059000336974084106433.mp4" id="video" class="video" />
  </div>
</template>
<script setup>
import { ref } from 'vue';

const offsetLeft = ref('258px'); //起始偏移量，结合css保证垂直居中
const offsetTop = ref('222px'); //起始偏移量，结合css保证水平居中
function bodyScroll(event){
  event.preventDefault();
}
const dragDiv = () => {
  document.ontouchmove = (e) => {
    const screenWidth = document.documentElement.clientWidth
    const screenHeight = document.documentElement.clientHeight
    document.body.addEventListener('touchmove',bodyScroll,false);
    document.body.style.position='fixed';
    document.body.style.overflow='hidden';
    document.body.style.width='100vw';
    document.body.style.height='100vh';
    let x = e.touches[0].pageX;
    let y = e.touches[0].pageY;
    if(x < 42) x = 42
    if(x > screenWidth - 42 ) x = screenWidth - 42
    if(y < 56) y = 56
    if(y > screenHeight - 56 ) y = screenHeight - 56
    offsetLeft.value = x > 0 ? `${Math.abs(x) - 42}px` : `-${Math.abs(x) -42 }px`;
    offsetTop.value = y > 0 ? `${Math.abs(y) - 56}px` : `-${Math.abs(y) -56}px`;
  };
}

const dragUp = () => {
  document.body.removeEventListener('touchmove',bodyScroll,false);
  document.body.style.position='initial';
  document.body.style.overflow='auto';
  document.body.style.width='auto';
  document.body.style.height='auto';
  document.ontouchmove = null;
}
</script>
<style lang="scss" scoped>
.video-wrapper {
  width: 84px;
  // height: 130px;
  position: fixed;
  border-radius: 10px;
  border: 1px solid #C95228;
  box-sizing: border-box;
  z-index: 1;
  top: v-bind(offsetTop);
  left: v-bind(offsetLeft);

  .video {
    width: 84px;
    height: 112px;
    overflow: hidden;
  }

  .show-div {
    height: 20px;
    background: linear-gradient(90deg, #C95228 0%, #DA5C2E 100%);
    border-radius: 0px 0px 10px 10px;
    display: flex;
    justify-content: center;
    box-sizing: border-box;
    padding-top: 2px;

    .text-img {
      width: 55px;
      height: 14px;
    }

  }

  .close-img {
    width: 20px;
    height: 21px;
    position: absolute;
    top: 2px;
    right: 3px;
    z-index: 2;
  }
}
</style>